package com.hall.items.ctrl;

import com.hall.items.aggr.MyEquipType;
import com.hall.items.aggr.MyWeaponArchive;
import com.hall.items.ctrl.vo.MyWeaponArchiveGMVO;
import com.hall.items.msg.MsgSender;
import com.hall.items.service.ItemsService;
import com.sharecommon.view.CommonVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/itemsgm")
public class ItemsGMController {

    @Autowired
    private ItemsService itemsService;

    @Autowired
    private MsgSender msgSender;

    @RequestMapping("/createequiptype")
    @ResponseBody
    public CommonVO createequiptype(int id, String code) {
        MyEquipType myEquipType = itemsService.createEquipType(id, code);
        return CommonVO.success("equipTypeId", myEquipType.getId());
    }

    @RequestMapping("/allequiptype")
    @ResponseBody
    public CommonVO allequiptype() {
        List<MyEquipType> list = itemsService.queryAllEquipType();
        return CommonVO.success(list);
    }

    @RequestMapping("/createweaponarchive")
    @ResponseBody
    public CommonVO createweaponarchive(int id, String code, int equipTypeId) {
        MyWeaponArchive myWeaponArchive = itemsService.createWeaponArchive(id,
                code, equipTypeId);
        msgSender.sendProcess(false);
        return CommonVO.success("weaponArchiveId", myWeaponArchive.getId());
    }

    @RequestMapping("/allweaponarchive")
    @ResponseBody
    public CommonVO allweaponarchive() {
        List<MyWeaponArchive> list = itemsService.queryAllWeaponArchive();
        List<MyWeaponArchiveGMVO> vos = new ArrayList<>();
        for (MyWeaponArchive archive : list) {
            vos.add(new MyWeaponArchiveGMVO(archive));
        }
        return CommonVO.success(vos);
    }

    @RequestMapping("/giveweapon")
    @ResponseBody
    public CommonVO giveweapon(long playerid, int weaponarchiveid) {
        itemsService.createWeapon(weaponarchiveid, playerid);
        msgSender.sendProcess(false);
        return CommonVO.success();
    }

}
